/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.index.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.snail.starter.commons.exception.BizException;
import com.snail.server.database.engine.error.DatabaseEngineErrorCode;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;

/**
 *
 * @author zgadmin
 * @date 2025/8/28 16:32
 *
 */
@Getter
@ToString
public enum IndexTypeEnum implements IEnum<String> {

    INDEX("INDEX", "普通索引"),
    UNIQUE_INDEX("UNIQUE", "唯一索引"),
    ;

    private final String value;

    private final String desc;

    IndexTypeEnum(String value, String desc){
        this.value = value;
        this.desc = desc;
    }

    public static IndexTypeEnum getEnum(String value){
        if(null == value || "".equals(value)){
            throw BizException.of(DatabaseEngineErrorCode.INDEX_TYPE_NULL);
        }
        return Arrays.stream(values()).filter(e -> e.getValue().equalsIgnoreCase(value))
                .findFirst()
                .orElseThrow(() ->BizException.of(DatabaseEngineErrorCode.NOT_SUPPORT_INDEX_TYPE, new Object[]{value}));
    }

}